package states 
{
	import com.greensock.TweenLite;
	import org.despair2D.control.KeyboardManager;
	import org.despair2D.control.TouchManager;
	import org.despair2D.control.ZMouseEvent;
	import org.despair2D.debug.Logger;
	import org.despair2D.ui.DespairUI;
	import org.despair2D.ui.events.ManipulateEvent;
	import org.despair2D.ui.UIState;
	import org.despair2D.ui.puppet.NineScalePuppet;
	import assets.AssetsUI;

	
public class NineScaleState extends UIState
{

	
	override public function enter( stateArgs:Array ):void
	{
		var nineScale:NineScalePuppet
		trace(stateArgs)
		DespairUI.addNineScaleData((new (AssetsUI.IMG_nineScaleA)).bitmapData, 'nineScaleA', 5)
		
		this.fusion.move(200,200)
		
		nineScale = new NineScalePuppet('nineScaleA', 400, 200)
		this.fusion.addElement(nineScale,50,50)
		
		nineScale.addEventListener(ManipulateEvent.PRESS, function(e:ManipulateEvent):void{trace('PRESS')})
		nineScale.addEventListener(ManipulateEvent.RELEASE, function(e:ManipulateEvent):void { trace('RELEASE') } )
		nineScale.addEventListener(ManipulateEvent.OVER, function(e:ManipulateEvent):void { trace('OVER') } )
		nineScale.addEventListener(ManipulateEvent.LEAVE, function(e:ManipulateEvent):void{trace('LEAVE')})
		nineScale.addEventListener(ManipulateEvent.MOVE, function(e:ManipulateEvent):void { trace('MOVE') } )
		nineScale.addEventListener(ManipulateEvent.CLICK, function(e:ManipulateEvent):void { trace('CLICK') } )
		
		TweenLite.from(fusion, 2, { scaleX:0.1, scaleY:0.1 } )
		
		//DespairUI.addNullPressedListener(__onNullPressed)
		
		KeyboardManager.getInstance().getState().addPressListener('A', __onPrevState)
		KeyboardManager.getInstance().getState().addPressListener('D', __onNextState)
		
		TouchManager.getInstance().addEventListener(ZMouseEvent.MOUSE_RELEASE, rrrr)
	}
	
	override public function exit():void
	{
		KeyboardManager.getInstance().getState().removePressListener('A', __onPrevState)
		KeyboardManager.getInstance().getState().removePressListener('D', __onNextState)
		TweenLite.killTweensOf(fusion)
		//DespairUI.removeNullPressedListener(__onNullPressed)
		TouchManager.getInstance().removeEventListener(ZMouseEvent.MOUSE_RELEASE, rrrr)
	}
	
	
	
	/////////////////////////////////////////////////////////////////////////
	
	private function __onPrevState():void
	{
		this.fusion.setState(ImageState)
	}
	
	private function __onNextState():void
	{
		this.fusion.setState(StartingState)
	}
	
	private function __onNullPressed():void
	{
		Logger.reportMessage(this, 'NULL PRESSED !!');
		this.fusion.startDrag()
	}
	
	private function rrrr(e:ZMouseEvent):void
	{
		if (this.fusion.dragging)
		{
			this.fusion.stopDrag()
		}
	}
}

}